
<template>
  <div class="app-container">
    <van-nav-bar title="标题" fixed @click-left="goback">
      <template #left>
        <div v-show="$route.path !== '/home'">
          <van-icon name="arrow-left" />
          <span style="color: skyblue; margin-left: 10px">返回</span>
        </div>
      </template>

      <template #right>
        <van-icon name="search" size="18" />
      </template>
    </van-nav-bar>

    <!-- <h3>这是根组件</h3> -->
    <transition>
      <router-view></router-view>
    </transition>

    <van-tabbar v-model="active" route class="title">
      <van-tabbar-item to="/home" icon="home-o">首页</van-tabbar-item>
      <van-tabbar-item to="/member" icon="user-circle-o">会员</van-tabbar-item>
      <van-tabbar-item to="/shopcar" icon="cart-o"
        >购物车
        <van-badge>
          <template #content> {{ totalCount }}</template>
        </van-badge>
      </van-tabbar-item>

      <van-tabbar-item replace to="/set" icon="setting-o">设置</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      active: 0,
      flag: true,
    };
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
  },
  created() {
    if (this.$route.path === "/home") {
      this.flag = false;
    }
  },
  watch: {
    "$route.path": function (newValue, oldValue) {
      if (newValue === "/home") {
        this.flag = false;
      }
    },
  },
  computed: {
    ...mapGetters(["totalCount"]),
  },
};
</script>

<style scoped>
.app-container {
  overflow: hidden;

  padding-bottom: 50px;
}

h3 {
  color: pink;
  font-size: 20px;
}
.v-enter {
  opacity: 0;
  transform: translateX(100%);
}
.v-leave-to {
  opacity: 0;
  transform: translateX(-100%);
  position: absolute;
}
.v-enter-active,
.v-leave-active {
  transition: all 0.6s ease;
}

.van-badge {
  position: absolute;
  top: 0px;
  right: 122px;
}
</style>